import random
import time
from kafka import KafkaProducer
import json
# 定义卡扣编号列表、车牌号码列表、城市名列表、道路名列表、区县名列表
user_list = ['110', '111', '112', '113', '114']
microblog_list = ["全国广电新媒体集结发光",
                  "范玮琪 我丈夫是个正直的人",
                  "阿斯巴甜 致癌",
                  "2023年中国网络文明大会新闻发布会",
                  "姜广涛 开工",
                  "关晓彤帽子P掉了鹿晗品牌",
                  "多所高校停用微信支付"]

# 定义卡扣经纬度范围
tollgate_longitude_range = (116.2, 116.6)
tollgate_latitude_range = (39.8, 40.2)

# # 生成100条随机数据
data_list = []

# 创建生产者
producer = KafkaProducer(bootstrap_servers="master:9092,node2:9092,node2:9092")

for i in range(10000000):
    user_id = random.choice(user_list)
    action_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    microblog = random.choice(microblog_list)

    user_action = {
        "user_id": user_id,
        "action_time": action_time,
        "microblog": microblog
    }

    user_action_json = json.dumps(user_action, ensure_ascii=False)

    producer.send(topic="user_action", value=user_action_json.encode("UTF-8"))
    print(user_action_json)
    time.sleep(0.1)
